package api.components;

import java.awt.*;
import java.awt.image.BufferedImage;
import javax.swing.*;

import api.image.MyImage;


public class ImagePanel extends JPanel {
	private static final long serialVersionUID = 1L;
	private BufferedImage img;
	public MyImage image;
	
	Dimension imgSize;
	int border = 5;
	Point offset;
   

	public ImagePanel(MyImage image) {
		this.img = image.img;
		this.image = image;
		
		imgSize = new Dimension(img.getWidth(null) + border * 2 + 1, img.getHeight(null) + border * 2 + 1);
		setPreferredSize(imgSize);
		setMinimumSize(imgSize);
		setMaximumSize(imgSize);
		setSize(imgSize);
	}  
  
	public void paintComponent(Graphics g) {
		Dimension size = getSize();
		offset = new Point();
		
		offset.x = (size.width - imgSize.width) / 2;
		offset.y = (size.height - imgSize.height) / 2;
		g.clearRect(0, 0, size.width, size.height);
		
		g.drawRect(offset.x, offset.y, imgSize.width, imgSize.height); 
		g.drawImage( img, offset.x + border + 1, offset.y + border + 1, null);
	}
	
	
}
